package com.wsh.lab.listener;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

/**
 * @author wsh
 * @date 2021-11-09 00:56
 */
public class InitSpringFactoryListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent sce) {
        //这里将加载beans.xml加载到内存中,放到servletcontext中,名称可以随便取,这里取为SpringApplicationContext,
        ApplicationContext applicationContext = new ClassPathXmlApplicationContext("beans.xml");
        sce.getServletContext().setAttribute("SpringApplicationContext", applicationContext);
    }

    @Override
    public void contextDestroyed(ServletContextEvent sce) {
    }
}
